<?php
$page = isset($_GET['page']) ? $_GET['page'] : 1;
$page = max($page, 1);
$page = min($page, count($data));
$pre_page = $page - 1>1 ? $page-1: 1;
$next_page = $page + 1<count($data) ? $page+1 : count($data);
$cookie_arr = array();
if (isset($_COOKIE['history'])){
    $cookie_arr = explode(",", $_COOKIE['history']);
    foreach ($cookie_arr as $k => $value){
        if ($page-1 == $value){
            unset($cookie_arr[$k]);
        }
    }
    $cookie_arr[] = $page-1;
    setcookie("history",implode(",", $cookie_arr));
    if (count($cookie_arr)>6){
        array_shift($cookie_arr);
    }
}else{
    setcookie("history", $page);
    $cookie_arr[] = $page;
}
krsort($cookie_arr);
if (isset($_GET['action'])){
    if ($_GET['action'] == "clear"){
        setcookie("history","",time()-1);
        $cookie_arr = array();
    }
}
if($page==1){
    $pre="无";
    $next=$data[$page][2];
}
else if($page==count($data)){
    $pre=$data[$page-2][2];
    $next="无";
}
else{
    $pre=$data[$page-2][2];
    $next=$data[$page][2];
}

?>

